package com.service.business.utils;

import com.service.business.support.Language;
import org.apache.commons.lang3.StringUtils;

/**
 * <dl>
 * <dt>platform</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年05月13日</dd>
 * </dl>
 *
 * @author
 */
public class LanguageUtil {

    public static void deal() {
        String languge = Language.LANG.get();
        if (StringUtils.isBlank(languge) || !languge.contains("_")) {
            Language.LANG.set(I18nUtil.CLocale.zh_CN);
            return;
        }

        char[] charArr = languge.toCharArray();
        int len = charArr.length;
        boolean isSet = false;
        if (charArr[len - 1] >= 97 && charArr[len - 1] <= 122) {
            charArr[len - 1] -= 32;
            isSet = true;
        }
        if (charArr[len - 2] >= 97 && charArr[len - 1] <= 122) {
            charArr[len - 2] -= 32;
            isSet = true;
        }

        if (isSet) {
            languge = new String(charArr);
            Language.LANG.set(languge);
        }

        if (!I18nUtil.CLocale.contain(languge)){
            Language.LANG.set(I18nUtil.CLocale.zh_CN);
        }

    }

}
